package com.cncsi.web;

import com.cncsi.entity.Org;
import com.cncsi.entity.zTree;
import com.cncsi.service.OrgService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * 部门管理Controller
 * 2018年9月11日, AM 08:52:14
 *
 * @author 姜文
 */
@Controller
@RequestMapping("/org")
public class OrgController {

    @Autowired
    private OrgService orgService;

    @RequestMapping(value = "/toOrgIndex", method = RequestMethod.GET)
    public String toOrgIndex(Map<String, Object> map) {
        List<zTree> list = orgService.OrgTree();
        map.put("zTree", list);
        return "org/org_index";
    }

    @ResponseBody
    @GetMapping("/getOrg/{orgId}")
    public Org getOrg(@PathVariable String orgId) {
        Org org = orgService.FindOneOrg(orgId);
        return org;
    }

    @ResponseBody
    @PostMapping("/deleteOrg")
    public String deleteOrg(String orgId) {
        String result = orgService.deleteOrg(orgId);
        return result;
    }

    @ResponseBody
    @PostMapping("/saveOrg")
    public String saveOrg(Org org) {
        String result = orgService.saveOrg(org);
        return result;
    }

    @ResponseBody
    @PostMapping("/updateOrg")
    public String updateOrg(Org org) {
        String result = orgService.updateOrg(org);
        return result;

    }
}
